﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace WeiXinSDK.Common
{
	public static class ObjectExt
	{

		public static string ToJson(this object obj)
		{
			return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
		}

		public static string ToXml(this object obj)
		{
			using (var stream = new MemoryStream())
			{
				new XmlSerializer(obj.GetType()).Serialize(stream, obj);
				stream.Position = 0;
				using (StreamReader reader = new StreamReader(stream))
				{
					return reader.ReadToEnd();
				}
			}

		}
	}
}
